<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('模型管理列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>模型名称：</label>
                                <input type="text" name="name"/>
                            </li>
<!--                            <li>-->
<!--                                <label>名称：</label>-->
<!--                                <input type="text" name="projName"/>-->
<!--                            </li>-->
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:model:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:model:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:model:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
<!--                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:model:export">-->
<!--                    <i class="fa fa-download"></i> 导出-->
<!--                </a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>

    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:model:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:model:remove')}]];
        var datas = [[${@dict.getType('fx_model_run_status')}]];

        var prefix = ctx + "system/model";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                openUrl: prefix + "/start/{id}",
                closeUrl: prefix + "/stop/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "模型管理",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '主键id',
                    visible: false
                },
                {
                    field: 'name',
                    title: '模型名称'
                },
                // {
                //     field: 'projName',
                //     title: '名称'
                // },
                    {
                        field: 'startName',
                        title: '启动文件名'
                    },
                    {
                        field: 'url',
                        title: '预览地址'
                    },
                // {
                //     field: 'path',
                //     title: '模型位置'
                // },
                // {
                //     field: 'condaPath',
                //     title: 'conda库位置'
                // },


                // {
                //     field: 'modelName',
                //     title: '模型文件名'
                // },
                // {
                //     field: 'condaName',
                //     title: '环境文件名'
                // },
                {
                    field: 'runStatus',
                    title: '模型运行状态(0 停止 1 启动中 2 运行中)',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    },
                },
                // {
                //     field: 'modelStatus',
                //     title: '模型状态(0 压缩包 1 解压中 2 已解压)'
                // },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-primary btn-xs " href="javascript:void(0)" onclick="titleadd(\'启动\',\'' +row.id + '\')"><i class="fa fa-play"></i>启动</a> ');
                        actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="titleadd(\'关闭\',\'' +row.id + '\')"><i class="fa fa-pause"></i>关闭</a>');
                        actions.push('<a class="btn btn-warning btn-xs " href="javascript:void(0)"  onclick="previewAction(\'' +row.id + '\')"><i class="fa fa-eye"></i>预览</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        // 添加信息
        function titleadd(str,id) {
            if(str=='启动'){
                openUrls(id)
            }else {
                closeUrls(id)

            }

        }

        function previewAction(id){
            console.log("url"+id)
            window.open(prefix+"/preview?id="+id)
        }

        function openUrls(id) {
            var dataParam ;
            var tipMsg = "确定开启模型吗？";
            var url = $.common.isEmpty(id) ? table.options.openUrl.replace("{id}", "") : table.options.openUrl.replace("{id}", id);
           console.log(url)
            $.modal.confirm(tipMsg, function() {
                $.post(url, dataParam, function(result) {
                    if (result.code == web_status.SUCCESS) {
                        location.href="";
                    } else {
                        $.modal.alertError(result.msg);
                    }
                });

            });
        }
        function closeUrls(id) {
            var dataParam ;
            var tipMsg = "确定关闭模型吗？";
            var url = $.common.isEmpty(id) ? table.options.closeUrl.replace("{id}", "") : table.options.closeUrl.replace("{id}", id);
            console.log(url)
            $.modal.confirm(tipMsg, function() {
                $.post(url, dataParam, function(result) {
                    if (result.code == web_status.SUCCESS) {
                        location.href="";
                    } else {
                        $.modal.alertError(result.msg);
                    }
                });
            });
            return url;
        }
    </script>
</body>
</html>